import os

from fastapi.security import OAuth2PasswordBearer
from omegaconf import OmegaConf

config = OmegaConf.load("configs/application.yaml")
setting = config.setting

DEBUG = setting.debug
DEMO = setting.demo

BASE_PATH = setting.path.base_path

WORK_PATH = setting.path.work_path
LOGS_PATH = setting.path.logs_path
TEMP_PATH = setting.path.temp_path

STATICS_PATH = setting.statics.path
STATICS_URL = setting.statics.urls

"""安全的随机密钥，该密钥将用于对 JWT 令牌进行签名"""
SECRET_KEY = setting.auth.jwt.secret_key
"""用于设定 JWT 令牌签名算法"""
ALGORITHM = setting.auth.jwt.algorithm
"""access_token 过期时间，一天"""
ACCESS_TOKEN_EXPIRE_MINUTES = setting.auth.access_token_expire_minutes
"""refresh_token 过期时间，用于刷新token使用，两天"""
REFRESH_TOKEN_EXPIRE_MINUTES = setting.auth.refresh_token_expire_minutes
"""access_token 缓存时间，用于刷新token使用，30分钟"""
ACCESS_TOKEN_CACHE_MINUTES = setting.auth.access_token_cache_minutes
LOGIN_LOG_RECORD = setting.auth.login_log_record

OAUTH_ENABLE = setting.auth.oauth_enable
OAUTH2_SCHEME = OAuth2PasswordBearer(tokenUrl="/auth/api/login", auto_error=False) if OAUTH_ENABLE else lambda: ""

IP_PARSE_ENABLE = setting.ip_parse.enable
IP_PARSE_TOKEN = setting.ip_parse.token